package com.np.adapterdemo1;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SimpleAdapterSecondActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.activity_simple_adapter_second, new String[]{"title", "info", "img"}, new int[]{R.id.title, R.id.info, R.id.img});
        setListAdapter(adapter);
    }

    private List<Map<String, Object>> getData() {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("title", "华为");
        map.put("info", "遥遥领先！");
        map.put("img", R.drawable.ic_launcher_background);
        list.add(map);

        map = new HashMap<>();
        map.put("title", "苹果");
        map.put("info", "Make America Great Again!");
        map.put("img", R.drawable.ic_launcher_background);
        list.add(map);

        map = new HashMap<>();
        map.put("title", "三星");
        map.put("info", "电池绝对不会爆炸思密达！");
        map.put("img", R.drawable.ic_launcher_background);
        list.add(map);

        return list;
    }
}